home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Newswatcher 2.0b22 / NW Source / Source / menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  4.8 KB  |  159 lines  |  [TEXT/MMCC]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     menus.c
  4.  
  5.     This module manges the menus.
  6.     
  7.     Copyright © 1994, Northwestern University.
  8.  
  9. ----------------------------------------------------------------------------*/
  10.  
  11. #include "glob.h"
  12. #include "menus.h"
  13. #include "menuutil.h"
  14. #include "strutil.h"
  15.  
  16.  
  17.  
  18. /*----------------------------------------------------------------------------
  19.     SetMenusTo
  20.     
  21.     Set the menus to a given state.
  22.     
  23.     Entry:    newAppleMenuState = new Apple menu enable/disable flags.
  24.             newFileMenuState = new File menu enable/disable flags.
  25.             newEditMenuState = new Edit menu enable/disable flags.
  26.             newNewsMenuState = new News menu enable/disable flags.
  27.             newSpecialMenuState = new Special menu enable/disable flags.
  28.             newWindMenuState = new Windows menu enable/disable flags.
  29. ----------------------------------------------------------------------------*/
  30.  
  31. void SetMenusTo (
  32.     unsigned long newAppleMenuState,
  33.     unsigned long newFileMenuState, 
  34.     unsigned long newEditMenuState,
  35.     unsigned long newNewsMenuState, 
  36.     unsigned long newSpecialMenuState, 
  37.     unsigned long newWindMenuState)
  38. {
  39.     Boolean r0, r1, r2, r3 ,r4, r5;
  40.     static unsigned long appleMenuState = 0;
  41.     static unsigned long fileMenuState = 0;
  42.     static unsigned long editMenuState = 0;
  43.     static unsigned long newsMenuState = 0;
  44.     static unsigned long specialMenuState = 0;
  45.     static unsigned long windMenuState = 0;
  46.  
  47.     r0 = AdjustOneMenu(kAppleMenu, 31, &appleMenuState, newAppleMenuState);
  48.     r1 = AdjustOneMenu(kFileMenu, kNumFileMenuItems, &fileMenuState, newFileMenuState);
  49.     r2 = AdjustOneMenu(kEditMenu, kNumEditMenuItems, &editMenuState, newEditMenuState);
  50.     r3 = AdjustOneMenu(kNewsMenu, kNumNewsMenuItems, &newsMenuState, newNewsMenuState);
  51.     r4 = AdjustOneMenu(kSpecialMenu, kNumSpecialMenuItems, &specialMenuState, newSpecialMenuState);
  52.     r5 = AdjustOneMenu(kWindMenu, kNumWindMenuItems, &windMenuState, newWindMenuState);
  53.     if (r0 || r1 || r2 || r3 || r4 || r5) DrawMenuBar();
  54. }
  55.  
  56.  
  57.  
  58. /*----------------------------------------------------------------------------
  59.     SetWindowsMenuShowHideFullGroupList
  60.     
  61.     Set the Windows menu command to "Show Full Group List" or 
  62.     "Hide Full Group List".
  63.     
  64.     Entry:    show = true to set to "Show Full Group List"
  65.                  = false to set to "Hide Full Group List"
  66. ----------------------------------------------------------------------------*/
  67.  
  68. void SetWindowsMenuShowHideFullGroupList (Boolean show)
  69. {
  70.     MenuHandle windMenu;
  71.     Str255 str;
  72.  
  73.     windMenu = GetMenuHandle(kWindMenu);
  74.     GetPString(show ? kStrShowFullGroupList : kStrHideFullGroupList, str);
  75.     SetMenuItemText(windMenu, kShowHideFullGroupListItem, str);
  76. }
  77.  
  78.  
  79.  
  80. /*----------------------------------------------------------------------------
  81.     SetEditMenuShowHideDetails
  82.     
  83.     Set the Edit menu command to "Show Details" or "Hide Details".
  84.     
  85.     Entry:    show = true to set to "Show Details"
  86.                  = false to set to "Hide Details"
  87. ----------------------------------------------------------------------------*/
  88.  
  89. void SetEditMenuShowHideDetails (Boolean show)
  90. {
  91.     MenuHandle editMenu;
  92.     Str255 str;
  93.  
  94.     editMenu = GetMenuHandle(kEditMenu);
  95.     GetPString(show ? kStrShowHeader : kStrHideHeader, str);
  96.     SetMenuItemText(editMenu, kShowHideDetailsItem, str);
  97. }
  98.  
  99.  
  100.  
  101. /*----------------------------------------------------------------------------
  102.     AdjustExtractBinariesCommand
  103.     
  104.     Adjust the "Extract Binaries" command in the "Special" menu.
  105.     The command should end in an ellipsis iff there is no default
  106.     download folder configured.
  107. ----------------------------------------------------------------------------*/
  108.  
  109. void AdjustExtractBinariesCommand (void)
  110. {
  111.     MenuHandle specialMenu;
  112.     Str255 str;
  113.     unsigned char len;
  114.     
  115.     specialMenu = GetMenuHandle(kSpecialMenu);
  116.     GetMenuItemText(specialMenu, kExtractBinariesItem, str);
  117.     len = str[0];
  118.     if (gPrefs.savedBinDefaultFolder && str[len] == '.') {
  119.         str[0] = len-3;
  120.         SetMenuItemText(specialMenu, kExtractBinariesItem, str);
  121.     } else if (!gPrefs.savedBinDefaultFolder && str[len] != '.') {
  122.         str[0] = len+3;
  123.         str[len+1] = str[len+2] = str[len+3] = '.';
  124.         SetMenuItemText(specialMenu, kExtractBinariesItem, str);
  125.     }
  126. }
  127.  
  128.  
  129.  
  130. /*----------------------------------------------------------------------------
  131.     AdjustCycleWindowsCommand
  132.     
  133.     Adjust the "Cycle Windows" command in the "Windows" menu.
  134.     The command should be enabled iff more than one visible window is open.
  135. ----------------------------------------------------------------------------*/
  136.  
  137. void AdjustCycleWindowsCommand (void)
  138. {
  139.     WindowPtr wind;
  140.     WindowPeek peek;
  141.     short numVis = 0;
  142.     MenuHandle windowsMenu;
  143.     
  144.     wind = FrontWindow();
  145.     while (wind != nil) {
  146.         peek = (WindowPeek)wind;
  147.         if (peek->visible) {
  148.             numVis++;
  149.             if (numVis >= 2) break;
  150.         }
  151.         wind = (WindowPtr)peek->nextWindow;
  152.     }
  153.     windowsMenu = GetMenuHandle(kWindMenu);
  154.     if (numVis >= 2) {
  155.         EnableItem(windowsMenu, kCycleWindowsItem);
  156.     } else {
  157.         DisableItem(windowsMenu, kCycleWindowsItem);
  158.     }
  159. }